<app>
    <h3 class="title">{ opts.title } </h3>
    <h5 class="score">{ sumscore }</h5>
    <div class="wrapper">
        <div id="answer" class="card_wrap" style="display:block">
            <!--Q1-->
            <div class="card_cont card{ di+1 }" each={ datasource,di in datas } style="z-index:{ items_length-di }" id="{ di }">
                <div class="card">
                    <p class="question"><span>Q{ di+1 }、</span>{ datasource.title }</p>
                    <ul class="select">
                        <li each={ item,j in datasource.items } >
                            <input id="{ di }-{ j }" type="radio" name="{ di }" current="{ di }" value="{ item.score }" onclick={ next }>
                            <label for="{ di }-{ j }" >{ item.desc }</label>
                        <li>
                    </ul>
                    <div class="card_bottom"><a class="prev" current="{ di }" onclick={ prev }>上一题</a><span><b>{ di+1 }</b>/{ items_length }</span></div>
                </div>
            </div>
            
        </div>
    </div>
 <script>
    self = this

    self.disabled = true

    self.datasources = opts.datasources

    //总分数
    self.sumscore = 0
    //已答题目数组
    self.scores = {}

    //题目总数量
    self.items_length = 0 

    //存储题目
    self.datas = []

    toggle(e){
        //- console.log(e.target.value)
        //- console.log(e.target.name)
        self.scores[e.target.name]=e.target.value

        //计算总分
        var sum = 0
        for(score in self.scores){
            console.log(score)
            sum = sum + parseInt(self.scores[score])
        }
        self.sumscore = sum
   
    }

    add(e) {
        console.log(self.sumscore)
        console.log(self.scores)
     
    }

    next(e){
        self.dddd = e

        var currentId = parseInt(e.target.attributes.current.value)
        console.log(currentId)
        if(currentId < self.items_length-3){
            setTimeout(function(){14
                document.getElementById(currentId).className="card_cont"
                document.getElementById(currentId+1).className="card_cont card1"
                document.getElementById(currentId+2).className="card_cont card2"
                document.getElementById(currentId+3).className="card_cont card3"
            },200)
        }
        if(currentId < self.items_length-2){
            setTimeout(function(){14
                document.getElementById(currentId).className="card_cont"
                document.getElementById(currentId+1).className="card_cont card1"
                document.getElementById(currentId+2).className="card_cont card2"
            },200)
        }
        if(currentId < self.items_length-1){
            setTimeout(function(){
                document.getElementById(currentId).className="card_cont"
                document.getElementById(currentId+1).className="card_cont card1"
            },200)
        }

        self.scores[e.target.name]=e.target.value

        //计算总分
        var sum = 0
        for(score in self.scores){
            //console.log(score)
            sum = sum + parseInt(self.scores[score])
        }
        self.sumscore = sum
        console.log(self.sumscore)
        //- self.update()
    }

    prev(e){

        var currentId = parseInt(e.target.attributes.current.value)
        console.log(currentId)
        //if(currentId != self.items_length-1){
            setTimeout(function(){
                document.getElementById(currentId-1).className="card_cont card1"
                document.getElementById(currentId).className="card_cont card2"
                document.getElementById(currentId+1).className="card_cont card3"
            },200)
        //}
    }

    //初始化 获取 题目数量
    self.init = function(){
        var items_length = 0 ;
        var lengths = self.datasources.length;
        for(var i =0 ;i<lengths;i++){
            items_length = items_length + self.datasources[i].data.length
        }
        for(var i = 0 ;i<lengths;i++){
            for(var j = 0;j < self.datasources[i].data.length ;j++){
                self.datas.push(self.datasources[i].data[j])
            }
        }

        self.items_length=items_length
    }

    self.on('mount',function(){
        self.init()
        console.log('init')
        self.update()
        //- $(function(){
        //-     $("#answer").answerSheet({});
        //- })
    })
  </script>
    
</app>